import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mac
 * Date: 2022-09-16
 * Time: 18:11
 */
class Card{
    private String rank;
    private String suit;

    public Card(String rank, String suit) {
        this.rank = rank;
        this.suit = suit;
    }

    @Override
    public String toString() {
        return "[ " + this.suit + " " + this.rank+ " ]";
    }
}
//没有大小王: 3 4 5 6 7 8 J Q K A
public class TestDemo2 {
    private static final String[] suits = {"♥","♠","♣","♦"};
    private static final String[] ranks = {"J", "Q", "K"};

    public static List<Card> buyCard() {
        ArrayList<Card> cards = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            cards.add(new Card("A",suits[i]));
            for (int j = 2; j <= 13; j++) {
                cards.add(new Card(j <= 10 ? j + "" : ranks[j - 11], suits[i]));
            }
        }
        return cards;
    }
    private static void swap(List<Card> cards,int i,int j){
        Card tmp = cards.get(i);
        cards.set(i,cards.get(j));
        cards.set(j,tmp);
    }
    public static void shuffle(List<Card> cards){
        int size = cards.size();
        for (int i = size - 1; i > 0; i--) {
            Random random = new Random();
            int rand = random.nextInt(i);
            swap(cards,i,rand);
        }
    }
    public static void getCard(List<Card> cards){
        ArrayList<ArrayList<Card>> hand = new ArrayList<>();

        ArrayList<Card> hand1 = new ArrayList<>();
        ArrayList<Card> hand2 = new ArrayList<>();
        ArrayList<Card> hand3 = new ArrayList<>();
        ArrayList<Card> hand4 = new ArrayList<>();
        ArrayList<Card> hand5 = new ArrayList<>();

        hand.add(hand1);
        hand.add(hand2);
        hand.add(hand3);
        hand.add(hand4);
        hand.add(hand5);

        //每个人轮流揭牌
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 5; j++) {
                Card card = cards.remove(0);
                hand.get(j).add(card);
            }
        }
        System.out.println("第一个人的牌："+hand1);
        System.out.println("第二个人的牌："+hand2);
        System.out.println("第三个人的牌："+hand3);
        System.out.println("第四个人的牌："+hand4);
        System.out.println("第五个人的牌："+hand5);
        System.out.println("剩下的牌："+cards);
    }
    public static void main(String[] args) {

        List<Card> cards = buyCard();//买牌
        System.out.println("买牌："+cards);

        shuffle(cards);//洗牌
        System.out.println("洗牌："+cards);

        System.out.println("炸金花：5个人每个人轮流接3张牌");
        getCard(cards);//发牌
    }

    public List<List<Integer>> generate(int numRows){
        List<List<Integer>> lists = new ArrayList<>();


        //第一行：
        List<Integer> list1 = new ArrayList<>();
        list1.add(1);
        lists.add(list1);

        for (int i = 1; i < numRows; i++) {
            List<Integer> list = new ArrayList<>();
            list.add(1);
            List<Integer> preRow = lists.get(i - 1);//上一行
            for (int j = 1; j < i; j++) {
                int num = preRow.get(j) + preRow.get(j - 1);
                list.add(num);
            }
            list.add(1);
            lists.add(list);
        }
        return lists;
    }
}
